package uebung04_h;

import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;
import javax.swing.JFrame;

import tools.ColorConversions;
import tools.Image;
import tools.ShowImage;

public class Tester01 {
	public static void main(String[] args) throws Exception {
		BufferedImage checker = ImageIO.read(Tester01.class.getClassLoader().getResourceAsStream("res/checkerrot.png"));
		
		final int w = checker.getWidth(), h = checker.getHeight();
		
		int[] pixels = checker.getRGB(0, 0, w, h, new int[w*h], 0, w);
		
		int[] grey = ColorConversions.getFastLuminance(pixels, new int[w*h]);
		
		double[] lum = Image.getScalarLuminance(grey, new double[w*h]);
		
		double[] dx = Image.conv(lum, w, h, Image.haargausxx, 2, 2, new double[w*h]);
		
		double max = Double.NEGATIVE_INFINITY, min = Double.POSITIVE_INFINITY;
		
		for (int i = 0; i<dx.length; i++) {
			max = Math.max(dx[i], max);
			min = Math.min(dx[i], min);
		}
 		System.out.println("max: "+max+" min: "+min);
		int[] ts = Image.prepare(dx, new int[w*h]);
		
		pixels = ColorConversions.buildRGB(ts, ts, ts, pixels);
		checker.setRGB(0,0, w,h, pixels, 0, w);
		
		JFrame ff = new JFrame();
		ff.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		ff.add(new ShowImage(checker));
		ff.pack();
		ff.setVisible(true);
		
		
	}
}
